var RS = {
	version : 'V1'
};
var layer;
var paths = document.location.pathname.split("/");
if (paths[0] == '') {
	RS.webPath = "/" + paths[1];
} else {
	RS.webPath = "/" + paths[0];
}

//获取表单数据的json字符串
RS.getFormData = function(formId) {
	return encodeURIComponent(JSON.stringify($('#' + formId).serializeJSON()));
};
// 获取表单数据的json数组
RS.getFormJsonString = function(formId) {
	return $('#' + formId).serializeJSON();
};
// 加载表单数据
RS.loadForm = function(formId, jsonValue) {
	jsonValue = jsonValue.rows[0];
	var obj = $('#' + formId);
	$.each(jsonValue, function(name, ival) {
		var $oinput = obj.find("[name='" + name + "']");
		if ($oinput.attr("type") == "radio" || $oinput.attr("type") == "checkbox") {
			$oinput.each(function() {
				if (Object.prototype.toString.apply(ival) == '[object Array]') {// 是复选框，并且是数组
					for (var i = 0; i < ival.length; i++) {
						if ($(this).val() == ival[i])
							$(this).attr("checked", "checked");
					}
				} else {
					if ($(this).val() == ival)
						$(this).attr("checked", "checked");
				}
			});
		} else if ($oinput.attr("type") == "textarea") {// 多行文本框
			obj.find("[name=" + name + "]").html(ival);
		} else {
			obj.find("[name=" + name + "]").val(ival);
		}
	});
}



Date.prototype.format = function(format) {
	var date = {
			"M+" : this.getMonth() + 1,
			"d+" : this.getDate(),
			"h+" : this.getHours(),
			"m+" : this.getMinutes(),
			"s+" : this.getSeconds(),
			"q+" : Math.floor((this.getMonth() + 3) / 3),
			"S+" : this.getMilliseconds()
	};
	if (/(y+)/i.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
	}
	for ( var k in date) {
		if (new RegExp("(" + k + ")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? date[k] : ("00" + date[k])
					.substr(("" + date[k]).length));
		}
	}
	return format;
}

// 时间戳格式化
var timeds = function(value, row, index) {
	var hangValue = "-";
	if (value == null) {
		return hangValue;
	} else {
		value = value+"";
		if (value.length == "13") {
			hangValue = new Date(parseInt(value)).format("yyyy-MM-dd hh:mm:ss");
		} else if (value.length == "10") {
			hangValue = new Date(parseInt(value) * 1000).format("yyyy-MM-dd hh:mm:ss");
		}
		return hangValue;
	}
}
